<?php
// +----------------------------------------------------------------------
// | OneKeyAdmin [ Believe that you can do better ]
// +----------------------------------------------------------------------
// | Copyright (c) 2020-2023 http://onekeyadmin.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: MUKE <513038996@qq.com>
// +----------------------------------------------------------------------
declare (strict_types = 1);

use plugins\cms\index\model\Product;
use plugins\cms\index\model\News;
use plugins\cms\index\model\Download;
use plugins\cms\index\model\Job;
use plugins\cms\index\model\Address;
use plugins\cms\index\model\Team;
/**
 * 产品列表
 */
function product(array $type = [], int $limit = 10, int $catalog_id = 0, array $order = ['sort' => 'desc', 'create_time' => 'desc']): object
{
    $where[] = ['status', '=', 1];
	foreach ($type as $k => $v) {
		$where[] = [$v, '=', 1];
	}
    if (! empty($catalog_id)) {
        $where[] = ["catalog_id", "find in set", $catalog_id];
    }
    return Product::where($where)->order($order)->limit($limit)->append(['url','catalog_title','cart_count'])->select();
}

/**
 * 新闻列表
 */
function news(array $type = [], int $limit = 10, int $catalog_id = 0, array $order = ['sort' => 'desc', 'create_time' => 'desc']): object
{
    $where[] = ['status', '=', 1]; 
    foreach ($type as $k => $v) {
        $where[] = [$v, '=', 1];
    }
    if (! empty($catalog_id)) {
        $where[] = ["catalog_id", "find in set", $catalog_id];
    }
	return News::where($where)->order($order)->limit($limit)->append(['url','content_images','comment_count','collect_count','catalog_title'])->select();
}

/**
 * 下载列表
 */
function down(array $type = [], int $limit = 10, int $catalog_id = 0, array $order = ['sort' => 'desc', 'create_time' => 'desc']): object
{
    $where[] = ['status', '=', 1]; 
    foreach ($type as $k => $v) {
        $where[] = [$v, '=', 1];
    }
    if (! empty($catalog_id)) {
        $where[] = ["catalog_id", "find in set", $catalog_id];
    }
    return Download::where($where)->order($order)->limit($limit)->append(['url','catalog_title','downloaded_url','downloaded_count'])->select();
}

/**
 * 招聘列表
 */
function job(array $type = [], int $limit = 10, int $catalog_id = 0, array $order = ['sort' => 'desc', 'create_time' => 'desc']): object
{
    $where[] = ['status', '=', 1]; 
    foreach ($type as $k => $v) {
        $where[] = [$v, '=', 1];
    }
    if (! empty($catalog_id)) {
        $where[] = ["catalog_id", "find in set", $catalog_id];
    }
    return Job::where($where)->order($order)->limit($limit)->append(['url','catalog_title','resume_count'])->select();
}

/**
 * 地址列表
 */
function address(array $type = [], int $limit = 10, int $catalog_id = 0, array $order = ['sort' => 'desc', 'create_time' => 'desc']): object
{
    $where[] = ['status', '=', 1]; 
    foreach ($type as $k => $v) {
        $where[] = [$v, '=', 1];
    }
    if (! empty($catalog_id)) {
        $where[] = ["catalog_id", "find in set", $catalog_id];
    }
    return Address::where($where)->order($order)->limit($limit)->append(['url','catalog_title'])->select();
}

/**
 * 团队列表
 */
function team(array $type = [], int $limit = 10, int $catalog_id = 0, array $order = ['sort' => 'desc', 'create_time' => 'desc']): object
{
    $where[] = ['status', '=', 1]; 
    foreach ($type as $k => $v) {
        $where[] = [$v, '=', 1];
    }
    if (! empty($catalog_id)) {
        $where[] = ["catalog_id", "find in set", $catalog_id];
    }
    return Team::where($where)->order($order)->limit($limit)->append(['url','catalog_title'])->select();
}